package taskTracker;

/**
 * Holds an interval of time
 * @author aseldawy
 *
 */
public class Interval {
	/**period in millis*/
	public final long period;

	public static Interval hours(int hours) {
		return new Interval(hours * 60 * 60 * 1000);
	}
	
	public static Interval minutes(int minutes) {
		return new Interval(minutes * 60 * 1000);
	}
	
	public Interval(long millis) {
		this.period = millis;
	}
	
	/**
	 * Converts it to string in humand readable format
	 */
	public String toString() {
		long temp = period;
		long hours = temp / 60 / 60 / 1000;
		temp -= hours * 60 * 60 * 1000;
		long minutes = temp / 60 / 1000;
		temp -= minutes * 60 * 1000;
		long seconds = temp / 1000;
		temp -= seconds * 1000;
		String str = "";
		if (hours > 0)
			str += hours +" hours ";
		if (minutes > 0)
			str += minutes + " minutes ";
		if (seconds > 0)
			str += seconds + " second ";
		if (temp > 0)
			str += temp + " millis";
		return str;
	}

	public boolean equals(Object obj) {
		return ((Interval)obj).period == this.period;
	}

	public int hashCode() {
		return (int)this.period * 13 % 9;
	}
}
